#include "vector.h"

namespace rtx
{
	void Test1()
	{
		vector<int> v;
		cout << v.size() << " " << v.capacity() << endl;
		v.push_back(1);
		v.push_back(2);
		v.push_back(3);
		v.push_back(4);
		cout << v.size() << " " << v.capacity() << endl;
        
		v.push_back(5);
		cout << v.size() << " " << v.capacity() << endl;

		for (size_t i = 0; i < v.size();++i)
		{
			cout << v[i] << " ";

		}
		cout << endl;
	}

	void Test2()
	{
		vector<int> v;
		v.push_back(1);
		v.push_back(2);
		v.push_back(3);
		v.push_back(4);
		v.push_back(5);

		for (size_t i = 0; i < v.size();++i)
		{
			++v[i];
			cout << v[i] << " ";
		}
		cout << endl;

		vector<int>::iterator it = v.begin();
		while (it != v.end())
		{
			--(*it);
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (const auto& e : v)
		{
			cout << e << " ";
		}
		cout << endl;

		string s("hello world");
		vector<int> v1(s.begin(), s.end());// 存了ASCII码
		for (const auto& e : v1)
		{
			cout << e << " ";
		}
		cout << endl;
	}

	void Test3()
	{
		vector<string> v;      // 在vector里放string
		v.push_back("1");
		v.push_back("2");
		v.push_back("3");
		v.push_back("4");
		v.push_back("5");
		v.push_back("6");
		v.push_back("7");
		v.push_back("8");
		v.push_back("9");

		for (const auto& e : v)
		{
			cout << e << " ";
		}
		cout << endl;
		cout << v.size() << " " << v.capacity() << endl;

		v.resize(50,"x");
		cout << v.size() << " " << v.capacity() << endl;

		v.pop_back();
		v.pop_back();
		v.pop_back();
		for (const auto& e : v)
		{
			cout << e << " ";
		}
		cout << endl;
		cout << v.size() << " " << v.capacity() << endl;
	}

	void Test4()
	{
		vector<int> v1;
		v1.push_back(1);
		v1.push_back(2);
		v1.push_back(3);
		vector<int>::iterator pos = find(v1.begin(), v1.end(), 2);
		if (pos != v1.end()) 
		{
			v1.insert(pos, 20);
		}
		for (const auto& e : v1)
		{
			cout << e << " "; 
		}
		cout << endl;

		pos = find(v1.begin(), v1.end(), 2);
		if (pos != v1.end())
		{
			v1.insert(pos, 20);
		}
		for (const auto& e : v1)
		{
			cout << e << " "; 
		}
		cout << endl;
	}

	void Test4_erase()
	{
		vector<int> v1;
		v1.push_back(1);
		v1.push_back(2);
		v1.push_back(3);
		v1.push_back(4);
		v1.push_back(5);
		vector<int>::iterator pos = v1.begin();// 删除v1所有的偶数
		while (pos != v1.end()) 
		{
			if (*pos % 2 == 0) 
			{
				pos = v1.erase(pos);
			}
			else
			{
				pos++;
			}
		}
		for (auto e : v1) 
		{
			cout << e << " ";
		}
		cout << endl;
	}

	void Tess5() 
	{
		vector<int> v1;
		v1.push_back(1);
		v1.push_back(2);
		v1.push_back(3);
		v1.push_back(4);
		v1.push_back(5);

		vector<int> v2(v1);
		for (const auto& e : v2)
		{
			cout << e << " ";
		}
		cout << endl;

		vector<int> v3;
		v3 = v2;
		for (auto e : v2)
		{
			cout << e << " ";
		}
		cout << endl;
	}
}

int main()
{
	rtx::Tess5();

	return 0;
}